#include "widget.h"
#include "ui_widget.h"
#include <QTextCodec>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    connect(&process,SIGNAL(started()),this,SLOT(started_slot()));//进程启动信号
    connect(&process,SIGNAL(readyRead()),this,SLOT(readyRead_slot()));//
    connect(&process,SIGNAL(finished(int)),this,SLOT(finished_solt(int)));//
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    process.start(ui->lineEdit->text());//启动进程
}
void Widget:: readyRead_slot(){
   QByteArray data = process.readAllStandardOutput();
   QString data_str = QTextCodec::codecForName("gbk")->toUnicode(data);//gbk->utf-8
   ui->textEdit->append(data_str);
}
void Widget:: started_slot(){
     ui->textEdit->append("started success");
}
void Widget::finished_solt(int exitCode){
    ui->textEdit->append(QString::number(exitCode));
}
